package swardToOffer.struct_3_linkedlist;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

/**
 * @Author ChanZany
 * @Date 2021/5/19 18:53
 * @Version 1.0
 * 面试题6：从尾到头打印链表
 * 题目：输入一个链表的头结点，从尾到头反过来打印出每个结点的值。
 */
@NoArgsConstructor
@AllArgsConstructor
class ListNode {
    int val;
    ListNode next;
    public ListNode(int val){
        this(val,null);
    }
}

public class PrintLinkedListReversely {
    void printLNR(ListNode head){
        if (head==null) return;
        printLNR(head.next);
        System.out.println(head.val);
    }

    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        head.next = new ListNode(2);
        head.next.next = new ListNode(3);
        new PrintLinkedListReversely().printLNR(head);
    }
}
